
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.Timer;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;


public class Play extends javax.swing.JFrame {
 Pro.Sound so;
 Timer timeplay;
 Integer second;
   Integer mini;
   static Object[][] con6=new Object[6][6];
    Object[] head6={"A","B","C","D","E","F"};
   static Object[][] con4=new Object[4][4];
    Object[] head4={"A","B","C","D"};
    boolean[][] canEdit4;
    boolean[][] canEdit6;
     ArrayList temp_ques;
    String temp_que;
    Object[][] temp4_puzz=new Object[4][4];
    Object[][] temp6_puzz=new Object[6][6];
    boolean playing;
    int[] tamthoi;
    /** Creates new form Play */
    public Play() {
        initComponents();
         so=new Pro.Sound("sound.wav");
         so.start();
         b1.setEnabled(false);
         showmain();
         this.button1.setEnabled(false);
         this.button2.setEnabled(false);
         second=0;
        mini=0;

        timeplay= new Timer(1000, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String temp=mini.toString();
                String temp2=second.toString();
                if(temp.length()==1)
                {
                    temp="0"+temp;
                }
                if(temp2.length()==1)
                {
                    temp2="0"+temp2;
                }
                if(second==59)
                {
                    time.setText(temp+" : "+temp2);
                    mini++;
                    second=0;
                }else
                {
                    time.setText(temp+" : "+temp2);
                    second++;
                }
            }
        });
    }

   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        high_sro = new javax.swing.JDialog();
        jLabel16 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tab = new javax.swing.JTable();
        jButton6 = new javax.swing.JButton();
        in_name = new javax.swing.JDialog();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txt1 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        in_name2 = new javax.swing.JDialog();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txt2 = new javax.swing.JTextField();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        b1 = new javax.swing.JButton();
        b22 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        button2 = new javax.swing.JButton();
        button1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        new4 = new javax.swing.JLayeredPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        play_game = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        play_b1 = new javax.swing.JButton();
        play_b2 = new javax.swing.JButton();
        b2 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        game_lab2 = new javax.swing.JLabel();
        game_lab3 = new javax.swing.JLabel();
        game_lab1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        time = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        play_t1 = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        game_lab4 = new javax.swing.JLabel();
        result = new javax.swing.JLayeredPane();
        jPanel8 = new javax.swing.JPanel();
        welcome_me = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        ta1 = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        ta2 = new javax.swing.JTable();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        gio = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txt = new javax.swing.JTextArea();

        high_sro.setTitle("High scores");

        jLabel16.setFont(new java.awt.Font("Tahoma", 2, 18));
        jLabel16.setForeground(new java.awt.Color(51, 0, 153));
        jLabel16.setText("High scores");

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("High scores"));

        tab.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Player", "Mark"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane6.setViewportView(tab);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton6.setText("Exit");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout high_sroLayout = new javax.swing.GroupLayout(high_sro.getContentPane());
        high_sro.getContentPane().setLayout(high_sroLayout);
        high_sroLayout.setHorizontalGroup(
            high_sroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(high_sroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(high_sroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(high_sroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(high_sroLayout.createSequentialGroup()
                            .addComponent(jLabel16)
                            .addGap(103, 103, 103))
                        .addGroup(high_sroLayout.createSequentialGroup()
                            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addContainerGap()))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, high_sroLayout.createSequentialGroup()
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(114, 114, 114))))
        );
        high_sroLayout.setVerticalGroup(
            high_sroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(high_sroLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        in_name.setTitle("Input your name !");

        jLabel9.setBackground(new java.awt.Color(0, 153, 255));
        jLabel9.setFont(new java.awt.Font("Tahoma", 2, 18));
        jLabel9.setForeground(new java.awt.Color(0, 51, 255));
        jLabel9.setText("Input your name");

        jLabel10.setText("Your name :");

        jButton3.setText("Ok");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Cancel");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout in_nameLayout = new javax.swing.GroupLayout(in_name.getContentPane());
        in_name.getContentPane().setLayout(in_nameLayout);
        in_nameLayout.setHorizontalGroup(
            in_nameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, in_nameLayout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(txt1, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                .addGap(44, 44, 44))
            .addGroup(in_nameLayout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(57, Short.MAX_VALUE))
            .addGroup(in_nameLayout.createSequentialGroup()
                .addGap(91, 91, 91)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(60, Short.MAX_VALUE))
        );
        in_nameLayout.setVerticalGroup(
            in_nameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(in_nameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(in_nameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(in_nameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        in_name2.setTitle("Input your name !");

        jLabel14.setBackground(new java.awt.Color(0, 204, 255));
        jLabel14.setFont(new java.awt.Font("Tahoma", 2, 18));
        jLabel14.setForeground(new java.awt.Color(51, 51, 255));
        jLabel14.setText("Input your name");

        jLabel15.setText("Your name :");

        jButton9.setText("Ok");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setText("Cancel");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout in_name2Layout = new javax.swing.GroupLayout(in_name2.getContentPane());
        in_name2.getContentPane().setLayout(in_name2Layout);
        in_name2Layout.setHorizontalGroup(
            in_name2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, in_name2Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jLabel15)
                .addGap(18, 18, 18)
                .addComponent(txt2, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                .addGap(44, 44, 44))
            .addGroup(in_name2Layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(57, Short.MAX_VALUE))
            .addGroup(in_name2Layout.createSequentialGroup()
                .addGap(94, 94, 94)
                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(60, Short.MAX_VALUE))
        );
        in_name2Layout.setVerticalGroup(
            in_name2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(in_name2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(in_name2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txt2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(in_name2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cross Word Game Player");
        setBackground(new java.awt.Color(0, 204, 255));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(0, 153, 255));

        b1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/play.jpg"))); // NOI18N
        b1.setToolTipText("Resume sound");
        b1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b1ActionPerformed(evt);
            }
        });

        b22.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pause.jpg"))); // NOI18N
        b22.setMnemonic('P');
        b22.setToolTipText("Pause Sound");
        b22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b22ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/new_game.jpg"))); // NOI18N
        jButton1.setToolTipText("New Game");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/high_sroc.jpg"))); // NOI18N
        jButton2.setToolTipText("Hight Scross");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        button2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pause_game.jpg"))); // NOI18N
        button2.setToolTipText("Pause Game");
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });

        button1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resume_game.jpg"))); // NOI18N
        button1.setToolTipText("Resume Game");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(b1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(b22, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(button2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                    .addComponent(button1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                    .addComponent(b1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(b22, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                .addGap(22, 22, 22))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 660, 90));

        jPanel2.setBackground(new java.awt.Color(0, 153, 255));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/player_pic.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jLabel1)
                .addContainerGap(36, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 90, 660, 350));

        new4.setBackground(new java.awt.Color(198, 219, 235));

        jPanel3.setBackground(new java.awt.Color(204, 204, 255));

        jScrollPane2.setBackground(new java.awt.Color(237, 254, 226));

        play_game.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane2.setViewportView(play_game);

        jPanel4.setBackground(new java.awt.Color(225, 225, 244));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Game control"));

        play_b1.setText("Pause");
        play_b1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                play_b1ActionPerformed(evt);
            }
        });

        play_b2.setText("Finish");
        play_b2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                play_b2ActionPerformed(evt);
            }
        });

        b2.setText("Reset");
        b2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(play_b1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(b2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(play_b2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(play_b2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(b2, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                        .addComponent(play_b1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel5.setBackground(new java.awt.Color(0, 204, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Puzzle information"));

        jLabel6.setText("Id of game");

        jLabel7.setText("Ownership of");

        game_lab2.setText("2");

        game_lab3.setText("3");

        game_lab1.setText("4");

        jLabel4.setText("Type of game");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(game_lab2, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                            .addComponent(game_lab3, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(37, 37, 37)
                        .addComponent(game_lab1, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(game_lab1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(game_lab2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(game_lab3)))
        );

        jPanel6.setBackground(new java.awt.Color(0, 204, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Timer"));

        time.setFont(new java.awt.Font("Times New Roman", 2, 36)); // NOI18N
        time.setText("00:00");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(time)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(time)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setText("Questopm");

        jScrollPane1.setBackground(new java.awt.Color(0, 153, 255));

        play_t1.setBackground(new java.awt.Color(0, 153, 255));
        play_t1.setColumns(20);
        play_t1.setEditable(false);
        play_t1.setRows(5);
        jScrollPane1.setViewportView(play_t1);

        jLabel8.setText("Puzzle name");

        game_lab4.setText("name");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2)
                        .addGap(130, 130, 130)
                        .addComponent(jLabel8)
                        .addGap(37, 37, 37)
                        .addComponent(game_lab4, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8)
                    .addComponent(game_lab4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel3.setBounds(0, 0, 660, 350);
        new4.add(jPanel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(new4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 90, 660, 350));

        jPanel8.setBackground(new java.awt.Color(0, 153, 255));

        welcome_me.setFont(new java.awt.Font("Tahoma", 2, 18)); // NOI18N
        welcome_me.setForeground(new java.awt.Color(255, 255, 255));
        welcome_me.setText("Hello guset");

        jScrollPane4.setBackground(new java.awt.Color(237, 254, 226));

        ta1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane4.setViewportView(ta1);

        jScrollPane5.setBackground(new java.awt.Color(237, 254, 226));

        ta2.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane5.setViewportView(ta2);

        jLabel12.setText("Our answer");

        jLabel11.setText("Your answer");

        jButton8.setText("View high scrore");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton7.setText("Back to main screen");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton5.setText("New game");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jPanel9.setBackground(new java.awt.Color(255, 255, 255));
        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Your playing time"));

        gio.setFont(new java.awt.Font("Times New Roman", 2, 36)); // NOI18N
        gio.setText("00:00");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(gio)
                .addContainerGap(44, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(gio)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel3.setText("Details");

        txt.setBackground(new java.awt.Color(0, 153, 255));
        txt.setColumns(20);
        txt.setEditable(false);
        txt.setRows(5);
        jScrollPane3.setViewportView(txt);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addGap(56, 56, 56)
                                .addComponent(jLabel11))
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addGap(18, 62, Short.MAX_VALUE)
                                .addComponent(jLabel12)
                                .addGap(136, 136, 136))
                            .addGroup(jPanel8Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addGap(67, 67, 67))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(welcome_me)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 402, Short.MAX_VALUE)))
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel3)
                        .addGap(78, 78, 78))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(welcome_me)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel11)
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(24, Short.MAX_VALUE))
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jPanel8.setBounds(0, 0, 660, 350);
        result.add(jPanel8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(result, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 90, 660, 350));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void b22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b22ActionPerformed
        // TODO add your handling code here:
        so.suspend();
        b22.setEnabled(false);
        b1.setEnabled(true);
    }//GEN-LAST:event_b22ActionPerformed

    private void b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b1ActionPerformed
        // TODO add your handling code here:
         so.resume();
        b22.setEnabled(true);
        b1.setEnabled(false);
    }//GEN-LAST:event_b1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        this.high_sro.setVisible(false);
}//GEN-LAST:event_jButton6ActionPerformed
public void showmain()
    {
    this.new4.setVisible(false);
    this.result.setVisible(false);
    this.jPanel2.setVisible(true);
}
public void showjlay(JLayeredPane lay)
    {
      this.new4.setVisible(false);
    this.result.setVisible(false);
    this.jPanel2.setVisible(false);
    lay.setVisible(true);
}
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
          try
          {
            ResultSet set = Database.playgame.get_highsc();
            int row = 0;
            while (set.next()) {
                tab.setValueAt(set.getString(1), row, 0);
                tab.setValueAt(set.getString(2), row, 1);
                row++;
            }
            this.high_sro.setSize(335,370);
            this.high_sro.setLocationRelativeTo(null);
            this.high_sro.setAlwaysOnTop(true);
            this.high_sro.setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            playing=true;
           if (timeplay.isRunning() == true) {
                timeplay.stop();
            }
            mini = 0;
            second = 0;
            button2.setEnabled(true);
            // TODO add your handling code here:
            Object[] data = new Object[2];
            data[0] = "New 4 x 4 Game";
            data[1] = "New 6 x 6 Game";
            int kq = JOptionPane.showOptionDialog(null, "Choose the type of game :", "Choose the type of game ", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, data, null);
            showjlay(new4);
            if (kq == 0) {
                //Puuzle 4x4
                ResultSet set = Database.playgame.getgame(4);
                try {
                    if (set.next()) {
                        this.game_lab1.setText(set.getString(4));
                        this.game_lab2.setText(set.getString(1));
                        this.game_lab3.setText(set.getString(3));
                        this.game_lab4.setText(set.getString(2));
                    }
                    set.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
                }
                con4 = Database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 4);
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        if (con4[i][j].equals("*")) {
                            canEdit4[i][j] = false;
                        } else {
                            canEdit4[i][j] = true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(197, 225, 236));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            } else {
                //Puzzle 6x6
                ResultSet set = Database.playgame.getgame(6);
                try {
                    if (set.next()) {
                        this.game_lab1.setText(set.getString(4));
                        this.game_lab2.setText(set.getString(1));
                        this.game_lab3.setText(set.getString(3));
                        this.game_lab4.setText(set.getString(2));
                    }
                    set.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
                }
                con6 = Database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 6);
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        if (con6[i][j].equals("*")) {
                            canEdit6[i][j] = false;
                        } else {
                            canEdit6[i][j] = true;
                        }
                    }
                }
                
                DefaultTableModel model = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(197, 225, 236));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
            //Set text question
            ResultSet re_set = Database.edit_puzzle.contenr(new Integer(game_lab2.getText()));
            String temp = "-----------" + "\n ---------------Your question--------------";
            int posi = 0;
            while (re_set.next()) {
                posi++;
                String que = re_set.getString(3);
                String anw = re_set.getString(4);
                String qtype = "Vertically";
                if (re_set.getInt(5) == 0) {
                    qtype = "Horizontal";
                }
                temp = temp + "\n    " + posi + ". " + que + ". ( " + qtype + " )";
            }
            re_set.close();
            this.play_t1.setText(temp);
            //set valida
            play_game.getModel().addTableModelListener(new TableModelListener() {

                @Override
                public void tableChanged(TableModelEvent e) {
                    //Event change in table
                    int row = e.getFirstRow();
                    int col = e.getColumn();
                    String kq = play_game.getValueAt(row, col).toString();
                    if (kq.length() == 0) {
                    } else if (kq.length() > 1) {
                        JOptionPane.showMessageDialog(null, "You must input only one character !", "Erroe", JOptionPane.ERROR_MESSAGE);
                        play_game.setValueAt("", row, col);
                    }
                }
            });
        } catch (Exception ex) {
            Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
        }
         timeplay.start();
    }//GEN-LAST:event_jButton1ActionPerformed
 public Object[][] getvalue_table(JTable ta)
    {
        Object[][] resu=new Object[ta.getRowCount()][ta.getRowCount()];
        for (int i = 0; i < ta.getRowCount(); i++) {
             for (int j = 0; j < ta.getRowCount(); j++) {
                resu[i][j]=ta.getValueAt(i, j);
            }
        }
        return resu;
    }
    private void play_b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_play_b1ActionPerformed
        // TODO add your handling code here:
        String butt=this.play_b1.getText();
        if(butt.equals("Resume")) {
            this.play_b1.setText("Pause");
            timeplay.start();
            this.button1.setEnabled(false);
            this.button2.setEnabled(true);
            this.b2.setEnabled(true);
            this.play_t1.setText(temp_que);
            //
            Integer type=new Integer(game_lab1.getText());
            if (type == 4) {
                //noidung4 = pro_database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 4);
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        if(con4[i][j].equals("*")) {
                            canEdit4[i][j] = false;
                        }else {
                            canEdit4[i][j]=true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(204, 255, 204));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            } else
            {
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        if(con6[i][j].equals("*")) {
                            canEdit6[i][j] = false;
                        }else {
                            canEdit6[i][j]=true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(204, 255, 204));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
            //set valida
            play_game.getModel().addTableModelListener(new TableModelListener() {

                @Override
                public void tableChanged(TableModelEvent e) {
                    //Event change in table
                    int row=e.getFirstRow();
                    int col=e.getColumn();
                    String kq=play_game.getValueAt(row, col).toString();
                    if(kq.length()==0) {
                    }else
                        if(kq.length()>1) {
                            JOptionPane.showMessageDialog(null, "You must input only one character !","Erroe",JOptionPane.ERROR_MESSAGE);
                            play_game.setValueAt("", row, col);
                        }

                }});
        }else {
            this.play_b1.setText("Resume");
            timeplay.stop();
            this.button1.setEnabled(true);
            this.button2.setEnabled(false);
            this.b2.setEnabled(false);
            ///
            temp_que=this.play_t1.getText();
            this.play_t1.setText("----------Game pause-------------");
            Integer type=new Integer(game_lab1.getText());
            int temp=type;
            if(temp==4) {
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        canEdit4[i][j] = false;
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(temp4_puzz, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                con4=getvalue_table(play_game);
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(225, 225, 244));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }else {
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        canEdit6[i][j] = false;
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(temp6_puzz, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                con6=getvalue_table(play_game);
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(225, 225, 244));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
            //
        }
    }//GEN-LAST:event_play_b1ActionPerformed

    private void play_b2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_play_b2ActionPerformed
        // TODO add your handling code here:
  this.in_name.setSize(315,170);
      this.in_name.setLocationRelativeTo(null);
      this.in_name.setAlwaysOnTop(true);
      this.in_name.setVisible(true);
}//GEN-LAST:event_play_b2ActionPerformed

    private void b2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b2ActionPerformed
        // TODO add your handling code here:
        if(this.b2.getText().equals("Position")) {
            this.b2.setText("Back");
            this.b2.setToolTipText("Back to User puzzle ");
            this.play_b1.setEnabled(false);
            this.button1.setEnabled(false);
            this.button2.setEnabled(false);
            Integer type=new Integer(game_lab1.getText());
            if (type == 4) {
                con4 = Database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 4);
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        canEdit4[i][j] = false;
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                con4=getvalue_table(play_game);
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(225, 225, 244));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            } else {
                con6 = Database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 6);
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        canEdit6[i][j] = false;
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                con6=getvalue_table(play_game);
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(225, 225, 244));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
        }else {
            this.b2.setText("Position");
            this.b2.setToolTipText("View positions of puzzle");
            this.play_b1.setEnabled(true);
            if(play_b1.getText().equals("Pause")) {
                this.button2.setEnabled(true);
            }else {
                this.button1.setEnabled(true);
            }
            //
            Integer type=new Integer(game_lab1.getText());
            if (type == 4) {
                //noidung4 = pro_database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 4);
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        if(con4[i][j].equals("*")) {
                            canEdit4[i][j] = false;
                        }else {
                            canEdit4[i][j]=true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(204, 255, 204));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            } else {
                // noidung6 = pro_database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 6);
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        if(con6[i][j].equals("*")) {
                            canEdit6[i][j] = false;
                        }else {
                            canEdit6[i][j]=true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(204, 255, 204));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
            //set valida
            play_game.getModel().addTableModelListener(new TableModelListener() {

                @Override
                public void tableChanged(TableModelEvent e) {
                    //Event change in table
                    int row=e.getFirstRow();
                    int col=e.getColumn();
                    String kq=play_game.getValueAt(row, col).toString();
                    if(kq.length()==0) {
                    }else
                        if(kq.length()>1) {
                            JOptionPane.showMessageDialog(null, "You must input only one character !","Erroe",JOptionPane.ERROR_MESSAGE);
                            play_game.setValueAt("", row, col);
                        }

                }});
        }
}//GEN-LAST:event_b2ActionPerformed

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
        // TODO add your handling code here:
         String butt=this.play_b1.getText();
        if(butt.equals("Resume")) {
            this.play_b1.setText("Pause");
            timeplay.start();
            this.button1.setEnabled(false);
            this.button2.setEnabled(true);
            this.b2.setEnabled(true);
            this.play_t1.setText(temp_que);
            ////
            Integer type=new Integer(game_lab1.getText());
            if (type == 4) {
                //noidung4 = pro_database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 4);
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        if(con4[i][j].equals("*")) {
                            canEdit4[i][j] = false;
                        }else {
                            canEdit4[i][j]=true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(204, 255, 204));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }}
    }//GEN-LAST:event_button1ActionPerformed

    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button2ActionPerformed
        // TODO add your handling code here:
         this.play_b1.setText("Resume");
            timeplay.stop();
            this.button1.setEnabled(true);
            this.button2.setEnabled(false);
            this.b2.setEnabled(false);
            ///
            temp_que=this.play_t1.getText();
            this.play_t1.setText("----------Game pause-------------");
            Integer type=new Integer(game_lab1.getText());
            int temp=type;
            if(temp==4) {
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        canEdit4[i][j] = false;
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(temp4_puzz, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                con4=getvalue_table(play_game);
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(225, 225, 244));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }else {
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        canEdit6[i][j] = false;
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(temp6_puzz, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                con6=getvalue_table(play_game);
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(225, 225, 244));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
            //
    }//GEN-LAST:event_button2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if(txt1.getText().equals("")) {
            JOptionPane.showMessageDialog(in_name, "You can not empty !","Error",JOptionPane.ERROR_MESSAGE);
        }else {
            this.button1.setEnabled(false);
             this.button2.setEnabled(false);
            playing=false;
            this.in_name.setVisible(false);
            String name=txt1.getText();
            this.welcome_me.setText("Hello "+name+" ! ");
            int secondes=(mini*60)+second;
            mini=0;
            second=0;
            ///test
            int type=new Integer(this.game_lab1.getText());
            if(type==4) {
                con4=getvalue_table(play_game);
                String temp="";
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        temp=temp+con4[i][j]+"-";
                    }
                }
                tamthoi=Pro.mark.getmark_ofplayer(secondes, temp, new Integer(game_lab2.getText()));
                int mark=tamthoi[0];
                int Puid=new Integer(game_lab2.getText());
                String status="Finish";
                Database.playgame.save_player_game(name, Puid, secondes, temp, status, mark);
                System.out.println("You want to save game?");
                ////hien len bang ket qua
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        canEdit4[i][j] = false;
                    }
                }
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                ta1.setModel(model);
                ta1.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                ta1.setFont(po);
                ta1.setBackground(new Color(225, 225, 244));
                ta1.setForeground(Color.LIGHT_GRAY);
                ta1.setCellSelectionEnabled(true);
                this.gio.setText(this.time.getText());
                ///
                con4=Database.edit_puzzle_4.getcellcontent(new Integer(game_lab2.getText()));
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        canEdit4[i][j] = false;
                    }
                }
                DefaultTableModel model2 = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                ta2.setModel(model2);
                ta2.setRowHeight(45);
                Font po2 = new Font("Time New Roman", Font.ITALIC, 30);
                ta2.setFont(po2);
                ta2.setBackground(new Color(225, 225, 244));
                ta2.setForeground(Color.LIGHT_GRAY);
                ta2.setCellSelectionEnabled(true);
                showjlay(result);
            }else {
                con6=getvalue_table(play_game);
                String temp="";
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        temp=temp+con6[i][j]+"-";
                    }
                }
                tamthoi=Pro.mark.getmark_ofplayer(secondes, temp, new Integer(game_lab2.getText()));
                int mark=tamthoi[0];
                int Puid=new Integer(game_lab2.getText());
                String status="Finish";
                Database.playgame.save_player_game(name, Puid, secondes, temp, status, mark);
                System.out.println("You want to save game?");
                ////hien len bang ket qua
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        canEdit6[i][j] = false;
                    }
                }
                DefaultTableModel model = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                ta1.setModel(model);
                ta1.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                ta1.setFont(po);
                ta1.setBackground(new Color(225, 225, 244));
                ta1.setForeground(Color.LIGHT_GRAY);
                ta1.setCellSelectionEnabled(true);
                this.gio.setText(this.time.getText());
                //
                con6=Database.edit_puzzle_6.getcellcontent(new Integer(game_lab2.getText()));
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        canEdit6[i][j] = false;
                    }
                }
                DefaultTableModel model2 = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                ta2.setModel(model2);
                ta2.setRowHeight(30);
                Font po2 = new Font("Time New Roman", Font.ITALIC, 30);
                ta2.setFont(po2);
                ta2.setBackground(new Color(225, 225, 244));
                ta2.setForeground(Color.LIGHT_GRAY);
                ta2.setCellSelectionEnabled(true);
                showjlay(result);
            }
            String deteil_text=play_t1.getText();
            deteil_text=deteil_text+"\n ----------------\n Total question :"+tamthoi[1]+"\n Your correct question :"+tamthoi[2]+"\n Your matk :"+tamthoi[0];
            this.txt.setText(deteil_text);
            mini=0;
            second=0;
        }
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        this.txt1.setText("");
        this.in_name.setVisible(false);
}//GEN-LAST:event_jButton4ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here:
        this.in_name2.setVisible(false);
        String name=txt2.getText();
        this.welcome_me.setText("Hello "+name+" ! ");
        int secondes=(mini*60)+second;
        mini=0;
        second=0;
        //test
        int type=new Integer(this.game_lab1.getText());
        if(type==4) {
            con4=getvalue_table(play_game);
            String temp="";
            for (int i = 0; i < head4.length; i++) {
                for (int j = 0; j < head4.length; j++) {
                    temp=temp+con4[i][j]+"-";
                }
            }
            tamthoi=Pro.mark.getmark_ofplayer(secondes, temp, new Integer(game_lab2.getText()));
            int mark=tamthoi[0];
            int Puid=new Integer(game_lab2.getText());
            String status="Pause";
            Database.playgame.save_player_game(name, Puid, secondes, temp, status, mark);
        }else {
            con6=getvalue_table(play_game);
            String temp="";
            for (int i = 0; i < head6.length; i++) {
                for (int j = 0; j < head6.length; j++) {
                    temp=temp+con6[i][j]+"-";
                }
            }
            tamthoi=Pro.mark.getmark_ofplayer(secondes, temp, new Integer(game_lab2.getText()));
            int mark=tamthoi[0];
            int Puid=new Integer(game_lab2.getText());
            String status="Pause";
            Database.playgame.save_player_game(name, Puid, secondes, temp, status, mark);
        }
        //
        System.exit(0);
}//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        // TODO add your handling code here:
        this.in_name2.setVisible(false);
}//GEN-LAST:event_jButton10ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
          try
        {
            ResultSet set = Database.playgame.get_highsc();
            int row = 0;
            while (set.next()) {
                tab.setValueAt(set.getString(1), row, 0);
                tab.setValueAt(set.getString(2), row, 1);
                row++;
            }
            this.high_sro.setSize(335,370);
            this.high_sro.setLocationRelativeTo(null);
            this.high_sro.setAlwaysOnTop(true);
            this.high_sro.setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jButton8ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
       showmain();
}//GEN-LAST:event_jButton7ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        try {
            playing=true;
           if (timeplay.isRunning() == true) {
                timeplay.stop();
            }
            mini = 0;
            second = 0;
            button2.setEnabled(true);
            // TODO add your handling code here:
            Object[] data = new Object[2];
            data[0] = " 4 x 4 Game";
            data[1] = " 6 x 6 Game";
            int kq = JOptionPane.showOptionDialog(null, "Choose the type of game :", "Choose the type of game ", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, data, null);
            showjlay(new4);
            if (kq == 0) {
                //Puzzle 4x4
                ResultSet set = Database.playgame.getgame(4);
                try {
                    if (set.next()) {
                        this.game_lab1.setText(set.getString(4));
                        this.game_lab2.setText(set.getString(1));
                        this.game_lab3.setText(set.getString(3));
                        this.game_lab4.setText(set.getString(2));
                    }
                    set.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
                }
                con4 = Database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 4);
                canEdit4 = new boolean[head4.length][head4.length];
                for (int i = 0; i < head4.length; i++) {
                    for (int j = 0; j < head4.length; j++) {
                        if (con4[i][j].equals("*")) {
                            canEdit4[i][j] = false;
                        } else {
                            canEdit4[i][j] = true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung4, tieude4);
                //bang_4x4.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con4, head4) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit4[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(45);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(197, 225, 236));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            } else {
                //Puuzle 6x6
                ResultSet set = Database.playgame.getgame(6);
                try {
                    if (set.next()) {
                        this.game_lab1.setText(set.getString(4));
                        this.game_lab2.setText(set.getString(1));
                        this.game_lab3.setText(set.getString(3));
                        this.game_lab4.setText(set.getString(2));
                    }
                    set.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
                }
                con6 = Database.playgame.getpuzzlecell_que(new Integer(game_lab2.getText()), 6);
                canEdit6 = new boolean[head6.length][head6.length];
                for (int i = 0; i < head6.length; i++) {
                    for (int j = 0; j < head6.length; j++) {
                        if (con6[i][j].equals("*")) {
                            canEdit6[i][j] = false;
                        } else {
                            canEdit6[i][j] = true;
                        }
                    }
                }
                //DefaultTableModel dai=new DefaultTableModel(noidung6, tieude6);
                //bang_6x6.setModel(dai);
                DefaultTableModel model = new DefaultTableModel(con6, head6) {

                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return canEdit6[rowIndex][columnIndex];
                    }
                };
                play_game.setModel(model);
                play_game.setRowHeight(30);
                Font po = new Font("Time New Roman", Font.ITALIC, 30);
                play_game.setFont(po);
                play_game.setBackground(new Color(197, 225, 236));
                play_game.setForeground(Color.LIGHT_GRAY);
                play_game.setCellSelectionEnabled(true);
            }
            //Set text question
            ResultSet re_set = Database.edit_puzzle.contenr(new Integer(game_lab2.getText()));
            String temp = "-----------" + "\n ---------------Your question--------------";
            int posi = 0;
            while (re_set.next()) {
                posi++;
                String que = re_set.getString(3);
                String anw = re_set.getString(4);
                String qtype = "Vertically";
                if (re_set.getInt(5) == 0) {
                    qtype = "Horizontal";
                }
                temp = temp + "\n    " + posi + ". " + que + ". ( " + qtype + " )";
            }
            re_set.close();
            this.play_t1.setText(temp);
            //set valida
            play_game.getModel().addTableModelListener(new TableModelListener() {

                @Override
                public void tableChanged(TableModelEvent e) {
                    //Event change in table
                    int row = e.getFirstRow();
                    int col = e.getColumn();
                    String kq = play_game.getValueAt(row, col).toString();
                    if (kq.length() == 0) {
                    } else if (kq.length() > 1) {
                        JOptionPane.showMessageDialog(null, "You must input only one character !", "Erroe", JOptionPane.ERROR_MESSAGE);
                        play_game.setValueAt("", row, col);
                    }
                }
            });
        } catch (Exception ex) {
            Logger.getLogger(Play.class.getName()).log(Level.SEVERE, null, ex);
        }
         timeplay.start();
}//GEN-LAST:event_jButton5ActionPerformed

    public static void main(String args[]) {
  Play obj=new Play();
  obj.setLocationRelativeTo(null);
  obj.setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b1;
    private javax.swing.JButton b2;
    private javax.swing.JButton b22;
    private javax.swing.JButton button1;
    private javax.swing.JButton button2;
    private javax.swing.JLabel game_lab1;
    private javax.swing.JLabel game_lab2;
    private javax.swing.JLabel game_lab3;
    private javax.swing.JLabel game_lab4;
    private javax.swing.JLabel gio;
    private javax.swing.JDialog high_sro;
    private javax.swing.JDialog in_name;
    private javax.swing.JDialog in_name2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JLayeredPane new4;
    private javax.swing.JButton play_b1;
    private javax.swing.JButton play_b2;
    private javax.swing.JTable play_game;
    private javax.swing.JTextArea play_t1;
    private javax.swing.JLayeredPane result;
    private javax.swing.JTable ta1;
    private javax.swing.JTable ta2;
    private javax.swing.JTable tab;
    private javax.swing.JLabel time;
    private javax.swing.JTextArea txt;
    private javax.swing.JTextField txt1;
    private javax.swing.JTextField txt2;
    private javax.swing.JLabel welcome_me;
    // End of variables declaration//GEN-END:variables

}
